home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 January / january_2000.iso / Site Building / HoTMetaL Pro / hm6ev.exe / data1.cab / Programming_Samples / Scripts / Template_Helpers / macros.txt < prev   
Encoding:
Text File  |  1999-10-15  |  6.1 KB  |  184 lines

  1. <MACRO name="On_Application_Open" lang="JScript"><![CDATA[
  2.   // Some useful constants
  3.   var viewWYSIWYG = 0;
  4.   var viewTagsOn = 1;
  5.   var viewSource = 2;
  6.  
  7.   // MoveToReplaceable - helper function for Previous/Next Replaceable macros
  8.   function MoveToReplaceable(dir) {
  9.     var rng = ActiveDocument.Range;
  10.     var foundCandidate;
  11.     var found = false;
  12.     do {
  13.       foundCandidate = rng.Find.Execute("<.PROCINS>", "", "", false, false, false, dir, false);
  14.       if (foundCandidate && (rng.Text.substring(0, 17) == "<?xm-replace_text")) {
  15.         found = true;
  16.       }
  17.     } while (!found && foundCandidate);
  18.     if (found) {
  19.       rng.Select();
  20.     }
  21.     else {
  22.       Application.Beep();
  23.     } 
  24.   }
  25. ]]></MACRO> 
  26.  
  27. <MACRO name="Previous Replaceable" lang="JScript" key="Ctrl+UpArrow"><![CDATA[
  28.   MoveToReplaceable(false);
  29. ]]></MACRO> 
  30.  
  31. <MACRO name="Next Replaceable" lang="JScript" key="Ctrl+DnArrow"><![CDATA[
  32.   MoveToReplaceable(true);
  33. ]]></MACRO> 
  34.  
  35. <MACRO name="Remove Readonly Section" lang="JScript" id="148"><![CDATA[
  36.  
  37.   // Remove the closest surrounding "readonly section" tags
  38.   function Do_RemoveReadonlySection() {
  39.     var rngDIV = ActiveDocument.Range;
  40.     var rngSPAN = rngDIV.Duplicate;
  41.  
  42.     // SPAN, then DIV
  43.     if (rngSPAN.isParentElement("SPAN")) {
  44.       rngSPAN.MoveToElement("SPAN", false);
  45.       if (rngSPAN.ContainerAttribute("CLASS") == "SQ-ReadOnly") {
  46.         rngSPAN.ReadOnlyContainer = false;
  47.         rngSPAN.RemoveContainerTags();
  48.         return;
  49.       }
  50.     }
  51.     if (rngDIV.isParentElement("DIV")) {
  52.       rngDIV.MoveToElement("DIV", false);
  53.       if (rngDIV.ContainerAttribute("CLASS") == "SQ-ReadOnly") {
  54.         rngDIV.ReadOnlyContainer = false;
  55.         rngDIV.RemoveContainerTags();
  56.         return;
  57.       }
  58.     }
  59.   }
  60.   
  61.   if (ActiveDocument.ViewType == viewWYSIWYG || ActiveDocument.ViewType == viewTagsOn) {
  62.     Do_RemoveReadonlySection();
  63.   }
  64. ]]></MACRO> 
  65.  
  66. <MACRO name="On_Document_Open_Complete" lang="JScript"><![CDATA[
  67.   function MarkReadOnlySections() {
  68.     // Mark special DIV and SPAN sections as read-only
  69.     var rng = ActiveDocument.Range;
  70.     var i;
  71.  
  72.     var nodeList = ActiveDocument.getElementsByTagName("DIV");
  73.     for (i = 0; i < nodeList.length; i++) {
  74.       var node = nodeList.item(i);
  75.       if (node.getAttribute("CLASS") == "SQ-ReadOnly") {
  76.         rng.SelectBeforeNode(node);
  77.         rng.MoveToElement("DIV");
  78.         rng.ReadOnlyContainer = true;
  79.       }
  80.     }
  81.  
  82.     nodeList = ActiveDocument.getElementsByTagName("SPAN");
  83.     for (i = 0; i < nodeList.length; i++) {
  84.       var node = nodeList.item(i);
  85.       if (node.getAttribute("CLASS") == "SQ-ReadOnly") {
  86.         rng.SelectBeforeNode(node);
  87.         rng.MoveToElement("SPAN");
  88.         rng.ReadOnlyContainer = true;
  89.       }
  90.     }
  91.   }
  92.  
  93.   // Read and save last modified date of file
  94.   var name = ActiveDocument.LocalFullName;
  95.   if (Application.ReadableFileExists(name)) {  // if document has never been saved, do nothing
  96.     var fso = new ActiveXObject("Scripting.FileSystemObject");
  97.     var f = fso.GetFile(name);
  98.     var mod = Date.parse(f.DateLastModified);
  99.     var props = ActiveDocument.CustomDocumentProperties;
  100.     props.Add("LastMod", mod);
  101.   }
  102.  
  103.   // Mark sections as readonly
  104.   if (ActiveDocument.ViewType == viewWYSIWYG || ActiveDocument.ViewType == viewTagsOn) {
  105.     MarkReadOnlySections();
  106.   }
  107. ]]></MACRO> 
  108.  
  109. <MACRO name="Make ReadOnly Section" lang="JScript" id="132"><![CDATA[
  110.   function Do_MakeReadOnlySection() {
  111.     // Check if we are in a view that works
  112.     var view = Application.ActiveDocument.ViewType;
  113.     if (view != viewWYSIWYG && view != viewTagsOn) {
  114.       var msg = "Can't make read-only section in this view.";
  115.       msg += "\nPlease switch to Tags On or WYSIWYG view and try again.";
  116.       Application.Alert(msg);
  117.       return;
  118.     }
  119.  
  120.     // Check if we have an extended selection
  121.     if (Selection.IsInsertionPoint) {
  122.       Application.Alert("Select some text and try again.");
  123.       return;
  124.     }
  125.  
  126.     if (Selection.CanSurround("DIV")) {
  127.       Selection.Surround("DIV");
  128.     }
  129.     else if (Selection.CanSurround("SPAN")) {
  130.       Selection.Surround("SPAN");
  131.     }
  132.     else { // impossible?
  133.       Application.Alert("Could not surround with a DIV or a SPAN tag.");
  134.       return;
  135.     }
  136.     Selection.ContainerAttribute("CLASS") = "SQ-ReadOnly";
  137.     Selection.ReadOnlyContainer = true;
  138.   }
  139.  
  140.   if (ActiveDocument.ViewType == viewWYSIWYG || ActiveDocument.ViewType == viewTagsOn) {
  141.     Do_MakeReadOnlySection();
  142.   }  
  143. ]]></MACRO> 
  144.  
  145. <MACRO name="Save As Template" lang="JScript" id="90"><![CDATA[
  146.   var obj = new ActiveXObject("HMExtras.FileDlg");
  147.   var filter = "Web Page Template (*.htm, *.html)|*.htm;*.html|All Files (*.*)|*.*||";
  148.   if (obj.DisplayFileDlg(0, "File Save As", filter, Application.Path + "\\Template")) {
  149.     ActiveDocument.SaveAs(obj.FullPathName, true); // save and put on recent file list  
  150.   }
  151. ]]></MACRO>
  152.  
  153. <MACRO name="MakeReplaceText" key="Ctrl+Alt+Z" lang="JScript" id="62" tooltip="Make Replace Text (Ctrl+Alt+Z)" desc="Makes current selection into replaceable text"><![CDATA[
  154.   function Do_MakeReplaceText() {
  155.     // Check if we are in a view that works
  156.     var view = Application.ActiveDocument.ViewType;
  157.     if (view != viewWYSIWYG && view != viewTagsOn) {
  158.       var msg = "Can't make replaceable text in this view.";
  159.       msg += "\nPlease switch to Tags On or WYSIWYG view and try again.";
  160.       Application.Alert(msg);
  161.       return;
  162.     }
  163.  
  164.     // Check if we have an extended selection
  165.     if (Selection.IsInsertionPoint) {
  166.       Application.Alert("Select some text and try again.");
  167.       return;
  168.     }
  169.  
  170.     // Handle replace text that is alread there in the selection
  171.     // This is not perfect: if there are other PI's it will fail.
  172.     // But it should be plenty good enough for HTML.
  173.     var txt = Selection.Text;
  174.     var exp = new RegExp("<\\?xm-replace_text ", "g");
  175.     txt = txt.replace(exp, "");
  176.     exp.compile("\\?>", "g");
  177.     txt = txt.replace(exp, "");
  178.     Selection.InsertReplaceableText(txt);
  179.   }
  180.   
  181.   Do_MakeReplaceText(); // Put it into a function for easier error handling
  182. ]]></MACRO> 
  183.  
  184.